package cn.picclife.mwx.app.util;

import java.io.File;
import java.net.URL;
import java.util.List;

import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.model.Bucket;
import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest;
import com.amazonaws.services.s3.model.GetObjectRequest;
import com.amazonaws.services.s3.model.PutObjectRequest;
import com.amazonaws.services.s3.model.S3Object;

public class SimpleFileUploadTest {

	private static AmazonS3 conn = null;
	private static String bucketName = "shuanglu-sys-bucket";

	private static String key = "新建文本文档.txt";
	private static String localFilePath = "d:/新建文本文档.txt";

	//private static ExecutorService executorService = Executors.newFixedThreadPool(5);
	//private static List<PartETag> partETags = Collections.synchronizedList(new ArrayList<PartETag>());

	
	public static void main(String[] args) {

		conn = AmazonS3Utils.getAmazonS3Instance();
		
		conn.putObject(new PutObjectRequest(bucketName, key, new File(localFilePath))); 
		
        S3Object object = conn.getObject(new GetObjectRequest(bucketName, key));  
       
        //获取一个request  
        GeneratePresignedUrlRequest urlRequest = new GeneratePresignedUrlRequest(bucketName, key);  
         
        //生成公用的url  
        URL url = conn.generatePresignedUrl(urlRequest); 
        //System.out.println("=========URL=================" + url + "============URL=============");  
        

	}
	
	public static void listBucket() {
		List<Bucket> buckets = conn.listBuckets();
		for(Bucket bucket :buckets) {
			//System.out.println(bucket.getName()+","+bucket.getOwner()+","+bucket.getCreationDate());
		}
	}

}
